package com.ads.proplan.activity;

import com.ads.proplan.R;
import com.ads.proplan.control.StatisticControl;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class EstatisticaFragment extends Fragment{
	
private StatisticControl control;
	
	private View rootView;
	
	public static final String ARG_OBJECT = "object";

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.activity_statistics,container, false);
		Bundle args = getArguments();
		getControl();
		setElementos();
		//((TextView) rootView.findViewById(android.R.id.text1)).setText(Integer.toString(args.getInt(ARG_OBJECT)));
		return rootView;
	}
			
	@Override
	public void onStop() {
		super.onStop();
		control.finalizeControl();
	}
	
//	@Override
//	public void onBackPressed() {
//		super.onBackPressed();
//		control.finalizeControl();
//	}

	public void getControl() {
		control = StatisticControl.getInstance();
		control.initialControl(this.getActivity());
	}

	public void setElementos() {
		if(control.getRespondidas() != 0){
			((TextView) rootView.findViewById(R.id.statistics_text_result_respondidas)).setText(""+control.getRespondidas());
			((TextView) rootView.findViewById(R.id.statistics_text_result_acerto)).setText(""+control.getAcertos());
			((TextView) rootView.findViewById(R.id.statistics_text_result_erros)).setText(""+control.getErros());
			((TextView) rootView.findViewById(R.id.statistics_text_result_aproveitamento)).setText(""+control.getAproveitamento()+"%");
			((TextView) rootView.findViewById(R.id.statistics_text_result_pontos)).setText(""+control.getPontos()+"p");
			((TextView) rootView.findViewById(R.id.statistics_text_result_serie)).setText(""+control.getSerie());
			((TextView) rootView.findViewById(R.id.statistics_text_result_rapida)).setText(""+control.getRapida()+"s");
			((TextView) rootView.findViewById(R.id.statistics_text_result_media)).setText(""+control.getMedia()+"s");
			((TextView) rootView.findViewById(R.id.statistics_text_result_jogadas)).setText(""+control.getNumeroPartidas());
			((TextView) rootView.findViewById(R.id.statistics_text_result_mpontuacao)).setText(""+control.getMaiorPonto());
		}
	}
}
